package com.inei.model.dao;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.inei.model.connection.UtilDB;
import com.inei.model.entity.MarcoCenso;

public class MarcoCensoDao implements ICRUD<MarcoCenso> {

	// variables
	private UtilDB util;
	private SQLiteDatabase db;
	private Cursor cursor = null;
	private Context context;

	public MarcoCensoDao(Context context) {
		this.context = context;
		util = new UtilDB(context);
	}

	@Override
	public MarcoCenso buscar(MarcoCenso o) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<MarcoCenso> leer() {
		List<MarcoCenso> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery("select * from MarcoCenso", null);
		if (cursor.moveToFirst()) {
			lista = new ArrayList<MarcoCenso>();
			while (!cursor.isAfterLast()) {
				MarcoCenso obj = new MarcoCenso();
				obj.setMarco_id(cursor.getInt(cursor.getColumnIndex("marco_id")));
				obj.setTipo_id(cursor.getInt(cursor.getColumnIndex("tipo_id")));
				obj.setNom_tipo(cursor.getString(cursor
						.getColumnIndex("nom_tipo")));
				obj.setCcdd(cursor.getString(cursor.getColumnIndex("ccdd")));
				obj.setNom_dpto(cursor.getString(cursor
						.getColumnIndex("nom_dpto")));
				obj.setCcpp(cursor.getString(cursor.getColumnIndex("ccpp")));
				obj.setNom_prov(cursor.getString(cursor
						.getColumnIndex("nom_prov")));
				obj.setCcdi(cursor.getString(cursor.getColumnIndex("ccdi")));
				obj.setNom_dist(cursor.getString(cursor
						.getColumnIndex("nom_dist")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	@Override
	public int crear(MarcoCenso o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int eliminar(MarcoCenso o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int actualizar(MarcoCenso o) {
		// TODO Auto-generated method stub
		return 0;
	}

	private void Cerrar() {
		if (cursor != null) {
			cursor.close();
		}
		if (db.inTransaction()) {
			db.endTransaction();
		}
		db.close();
	}
}
